for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
l1 = []
l2= [0] * 26
for ch in s:
l2 [ord(ch) - ord('a')]+= 1
for i in range(k):
x = 0
c = n//k
while l2[x] and c:
l2[x] -= 1
c -= 1
x += 1
l1.append(chr(x + ord('a')))
print(''.join(l1))
#include <bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for (auto i = (l) - ((l) > (r)); i != (r) - ((l) > (r)); i += 1 - 2 * ((l) > (r)))
#define all(a) begin(a), end(a)
#define sz(a) lli(a.size())
#define pb push_back
#define f first
#define s second
#ifdef LOCAL
#include "../debug.h"
#else
#define debug(...)
#endif
using lli = long long;
using ld = long double;
using ii = pair<lli, lli>;
const lli N = 1e6 + 5;
const lli INF = 4e18 + 5;
lli n, k;
string s;
template <class T>
bool umin(T& a, T b) {
return (a = min(a, b)) == b;
}
template <class T>
bool umax(T& a, T b) {
return (a = max(a, b)) == b;
}
void testCase() {
cin >> n >> k >> s;
map<char, lli> fr;
for (char c : s) {
fr[c]++;
}
fore (it, 0, k) {
lli cnt = 0;
fore (c, 0, 26) {
if (fr[c + 'a'] > 0) {
cnt++;
fr[c + 'a']--;
if (cnt == n / k) {
cout << char(c + 'a' + 1);
break;
}
} else {
cout << char(c + 'a');
break;
}
}
}
cout << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0), cout.tie(0);
lli tc = 1;
cin >> tc;
while (tc--) {
testCase();
}
return 0;
}
6. Zigzag Conversion | 1612B - Special Permutation |
1481. Least Number of Unique Integers after K Removals | 1035. Uncrossed Lines |
328. Odd Even Linked List | 1219. Path with Maximum Gold |
1268. Search Suggestions System | 841. Keys and Rooms |
152. Maximum Product Subarray | 337. House Robber III |
869. Reordered Power of 2 | 1593C - Save More Mice |
1217. Minimum Cost to Move Chips to The Same Position | 347. Top K Frequent Elements |
1503. Last Moment Before All Ants Fall Out of a Plank | 430. Flatten a Multilevel Doubly Linked List |
1290. Convert Binary Number in a Linked List to Integer | 1525. Number of Good Ways to Split a String |
72. Edit Distance | 563. Binary Tree Tilt |
1306. Jump Game III | 236. Lowest Common Ancestor of a Binary Tree |
790. Domino and Tromino Tiling | 878. Nth Magical Number |
2099. Find Subsequence of Length K With the Largest Sum | 1608A - Find Array |
416. Partition Equal Subset Sum | 1446. Consecutive Characters |
1618A - Polycarp and Sums of Subsequences | 1618B - Missing Bigram |